<template>
	<view class="view_desc_card">
		<view class="card_list" @click="goShopList">
			<template v-for="(item,index) in cols">
				<view v-if="(!item.show || item.show({recordType:data['record_type']}))" :key="index" class="card_item">
					<text class="item_label">{{ item.label }}</text>
					<text class="item_desc">{{data[item.key] || '-'}}</text>
				</view>
			</template>
		</view>
		<view class="card_bottom">
      <button @click="goScan">{{$t('common.scan')}}{{$t('erp.entryRoom')}}</button>
      <button type="primary" @click="goReferral">{{ $t('erp.arraign') }}</button>
		</view>
	</view>
</template>

<script>
	import { getConfig } from '../../config';
	import { toast, showConfirm, tansParams } from '@/utils/common'
	import { referral } from '@/api/index'
	export default {
		props:{
			pageName:{
				type:String,
				default: ''
			},
			data:{
				type:Object,
				default:()=>{
					return {}
				}
			}
		},
		emits:['initData'],
		data() {
			return { 
				cols:[]
			};
		}, 
		created(){
			const configInfo = getConfig()
			this.cols = configInfo.itemCols || []
		},
		methods:{
			async goScan(){
        this.$tab.navigateTo(`/pages/shop/add?recordId=${this.data.id}&type=${this.data.record_type}&pageName=${this.pageName}`)
			},
			async goShopList(){
        this.$tab.navigateTo(`/pages/shop/list?recordId=${this.data.id}&type=${this.data.record_type}&pageName=${this.pageName}`)
			},
			async goReferral(){
				showConfirm(`${this.$t('common.sure')}${this.$t('erp.arraign')}?`).then(async (res)=> {
          if (res.confirm) {
						try {
							const fData = {
								record_type:this.data.record_type,
								stock_record_ids:[this.data.id]
							}
							const {success,data,message} = await referral(fData)
							if (!success) {
								this.$modal.showToast(message || `${this.$t('erp.arraign')}${this.$t('common.success')}?`);
							}
							this.$modal.showToast(message || `${this.$t('erp.arraign')}${this.$t('common.fail')}?`);
							this.$emit('initData')
						} catch (error) {
							console.log('error',error)
						}
          }
        })
			},
		}
	}
</script>

<style lang="scss">
.view_desc_card{
	width: 100%;
	height: auto;
	.card_list{
		width: 100%;
		height: auto;
		padding: 20rpx 30rpx;
		.card_item{
			font-size: 24rpx;
			color: #999;
			text-align: justify;
			line-height: 34rpx;
			.item_label{
				display: inline-block;
				width: 6em;
				font-size: 26rpx;
				color: #333;
			}
			&+.card_item{
				margin-top: 10rpx;
			}
		}
	}
	.card_bottom{
		width: 100%;
		height: auto;
		border-top: 1rpx solid #dcdcdc;
		padding: 20rpx 30rpx;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		font-size: 24rpx;
		color: #666;
		line-height: 34rpx;
		text-align: justify;
		button{
			min-width: 140rpx;
			height: 60rpx;
			font-size: 24rpx;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-left: unset;
			margin-right: unset;
			&+button{
				margin-left: 20rpx;
			}
		}
	}
}

</style>
